package com.ymatou.iapi.productquery.compare;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.iapi.productquery.parameter.CatalogList.ProductInCartBean;
import com.ymatou.iapi.productquery.parameter.ProductDescExtra.ProductDescExtraBean;
import com.ymatou.iapi.productquery.parameter.ProductDetail.ProductInDetailBean;
import com.ymatou.iapi.productquery.parameter.ProductHistory.ProductHistoryBean;
import com.ymatou.iapi.productquery.parameter.ProductList.ProductInListBean;
import com.ymatou.iapi.productquery.parameter.RecommendProd.RecommendProductBean;
import com.ymatou.iapi.productquery.parameter.SecKill.SecKillProductActivityStockBean;
import com.ymatou.iapi.productquery.parameter.TopProduct.TopProductInLiveBean;
import com.ymttest.business.service.ProductQueryCallService;

public class SearchCompareCore {
	private static boolean preCheckJSONObject(JSONObject oldRet,JSONObject newRet, String sonKey,String desc,boolean isWrite) throws JSONException{
		if  (oldRet.isNull("Data")&&newRet.isNull("Data")){
			//do nothing
			return false;
		}
		
		if  (oldRet.isNull("Data")&&!newRet.isNull("Data")){
			LoggerHelper.verifyEquals(true, false, desc+", Data节点,老接口为null，新接口不为 null",isWrite);
			return false;
		}
		
		if  (!oldRet.isNull("Data")&&newRet.isNull("Data")){
			LoggerHelper.verifyEquals(true, false, desc+", Data节点,老接口不为null，新接口为 null",isWrite);
			return false;
		}
		
		
		if  (oldRet.getJSONObject("Data").isNull(sonKey)&&newRet.getJSONObject("Data").isNull(sonKey)){
			//do nothing
			return false;
		}
		
		
		if  (oldRet.getJSONObject("Data").isNull(sonKey)&&!newRet.getJSONObject("Data").isNull(sonKey)){
			LoggerHelper.verifyEquals(true, false, desc+", Data节点下["+sonKey +"]节点,老接口为null，新接口不为 null",isWrite);
			return false;
		}
		
		if  (!oldRet.getJSONObject("Data").isNull(sonKey)&&newRet.getJSONObject("Data").isNull(sonKey)){
			LoggerHelper.verifyEquals(true, false, desc+", Data节点下["+sonKey +"]节点,老接口不为null，新接口为 null",isWrite);
			return false;
		}
		
		return true;
		
	}
	
	
	
	
	
	
	public static ProductReturnBean coreCompareCatalogList(List<String> catalogs, boolean isTradeIsolation,boolean isWrite) {
		JSONObject old_ret;
		JSONObject new_ret;
		String apiName;

		if (isTradeIsolation) {
			old_ret = SearchCompareAPI.old_GetCatalogListByTradeIsolation().search(catalogs);
			new_ret = SearchCompareAPI.new_GetCatalogListByTradeIsolation().search(catalogs);
			apiName = "GetCatalogListByTradeIsolation";
		} else {
			old_ret = SearchCompareAPI.old_GetCatalogListByCatalogIdList().search(catalogs);
			new_ret = SearchCompareAPI.new_GetCatalogListByCatalogIdList().search(catalogs);
			apiName = "GetCatalogListByCatalogIdList";
		}

		apiName = apiName + ", catalogId: " + catalogs.get(0);
		try {
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");

			List<ProductInCartBean> old_ProductInCartBeanList = new ArrayList<>();
			List<ProductInCartBean> new_ProductInCartBeanList = new ArrayList<>();

			for (int i = 0; i < old_prodList.length(); i++) {
				old_ProductInCartBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),
						ProductInCartBean.class));
				new_ProductInCartBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),
						ProductInCartBean.class));

			}
			System.out.println(apiName);
			// 返回值比对
			return new ProductReturnBean(old_ProductInCartBeanList.get(0).getProductId(),
					SearchCompareHelper.compareProductInCartBean(old_ProductInCartBeanList.get(0),
							new_ProductInCartBeanList.get(0),
							apiName, isWrite));

		} catch (Exception e) {
			e.printStackTrace();
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;

	}

	public static ProductReturnBean coreCompareProductInfo(String productId, boolean isTradeIsolation,boolean isWrite) {
		JSONObject old_ret;
		JSONObject new_ret;
		String apiName;
		if (isTradeIsolation) {
			old_ret = SearchCompareAPI.old_GetProductInfoByTradeIsolation().search(Arrays.asList(productId));
			new_ret = SearchCompareAPI.new_GetProductInfoByTradeIsolation().search(Arrays.asList(productId));
			apiName = "GetProductInfoByTradeIsolation";
		} else {
			old_ret = SearchCompareAPI.old_GetProductInfoByProductId().search(Arrays.asList(productId));
			new_ret = SearchCompareAPI.new_GetProductInfoByProductId().search(Arrays.asList(productId));
			apiName = "GetProductInfoByProductId";
		}

		apiName = apiName + ",productId:" + productId;
		try {
			if (!preCheckJSONObject(old_ret,new_ret,"Product",apiName,isWrite)){return null;}
			
			JSONObject old_prod = old_ret.getJSONObject("Data").getJSONObject("Product");
			JSONObject new_prod = new_ret.getJSONObject("Data").getJSONObject("Product");

			ProductInDetailBean oldBean = ProductQueryCallService.getBeanFromJson(old_prod, ProductInDetailBean.class);
			ProductInDetailBean newBean = ProductQueryCallService.getBeanFromJson(new_prod, ProductInDetailBean.class);

			// 返回值比对
			System.out.println(apiName);
			return new ProductReturnBean(productId, SearchCompareHelper.compareProductInDetailBean(oldBean, newBean,
					apiName, isWrite));

		} catch (Exception e) {
			e.printStackTrace();
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;

	}

	public static ProductReturnBean coreCompareProductInfoList(List<String> productList, boolean isTradeIsolation,
			boolean isWrite) {
		JSONObject old_ret;
		JSONObject new_ret;
		String apiName;

		if (isTradeIsolation) {
			old_ret = SearchCompareAPI.old_GetProductDetailListByTradeIsolation().search(productList);
			new_ret = SearchCompareAPI.new_GetProductDetailListByTradeIsolation().search(productList);
			apiName = "GetProductDetailListByTradeIsolation";
		} else {
			old_ret = SearchCompareAPI.old_GetProductDetailListByProductIdList().search(productList);
			new_ret = SearchCompareAPI.new_GetProductDetailListByProductIdList().search(productList);
			apiName = "GetProductDetailListByProductIdList";
		}

		apiName = apiName + ",productId:" + productList.get(0);
		try {
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");

			List<ProductInDetailBean> old_ProductInDetailBeanList = new ArrayList<>();
			List<ProductInDetailBean> new_ProductInDetailBeanList = new ArrayList<>();

			for (int i = 0; i < old_prodList.length(); i++) {
				old_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),
						ProductInDetailBean.class));
				new_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),
						ProductInDetailBean.class));

			}
			System.out.println(apiName);
			return new ProductReturnBean(old_ProductInDetailBeanList.get(0).getProductId(),
					SearchCompareHelper.compareProductInDetailBean(old_ProductInDetailBeanList.get(0),
							new_ProductInDetailBeanList.get(0),
							apiName, isWrite));

		} catch (Exception e) {
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}

		return null;

	}

	public static ProductReturnBean coreCompareCatalogListByDeliveryExtra(List<String> catalogIdAndType,
			boolean isTradeIsolation, boolean isWrite) {
		JSONObject old_ret;
		JSONObject new_ret;
		String apiName;

		if (isTradeIsolation) {
			old_ret = SearchCompareAPI.old_GetCatalogListByDeliveryExtraIsolation().search(catalogIdAndType);
			new_ret = SearchCompareAPI.new_GetCatalogListByDeliveryExtraIsolation().search(catalogIdAndType);
			apiName = "GetCatalogListByDeliveryExtraIsolation";
		} else {
			old_ret = SearchCompareAPI.old_GetCatalogListByDeliveryExtra().search(catalogIdAndType);
			new_ret = SearchCompareAPI.new_GetCatalogListByDeliveryExtra().search(catalogIdAndType);
			apiName = "GetCatalogListByDeliveryExtra";
		}

		apiName = apiName + ", catalogId: " + catalogIdAndType.get(0)+", deliveryType: "+catalogIdAndType.get(1);
		try {
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			if (new_ret.getJSONObject("Data").getJSONArray("ProductList").length()==0){
				if (old_ret.getJSONObject("Data").getJSONArray("ProductList").getJSONObject(0).getInt("Status")>-1){
					LoggerHelper.failure(apiName + ", 新接口返回规格不存",true);
				}
				return null;
			}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");

			List<ProductInCartBean> old_ProductInCartForDeliveryBean = new ArrayList<>();
			List<ProductInCartBean> new_ProductInCartForDeliveryBean = new ArrayList<>();

			for (int i = 0; i < old_prodList.length(); i++) {
				old_ProductInCartForDeliveryBean.add(ProductQueryCallService
						.getBeanFromJson(old_prodList.getJSONObject(i), ProductInCartBean.class));
				new_ProductInCartForDeliveryBean.add(ProductQueryCallService
						.getBeanFromJson(new_prodList.getJSONObject(i), ProductInCartBean.class));
			}

			// 返回值比对
			System.out.println(apiName);
			return new ProductReturnBean(old_ProductInCartForDeliveryBean.get(0).getProductId(),
					SearchCompareHelper.compareProductInCartBean(old_ProductInCartForDeliveryBean.get(0),
							new_ProductInCartForDeliveryBean.get(0),apiName,isWrite));

		} catch (Exception e) {
			e.printStackTrace();
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage() + ",Old_Msg" + old_ret.getString("Msg") + ",New_Msg"
						+ new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;

	}

	public static ProductReturnBean coreCompareProductListList(List<String> productList, boolean isTradeIsolation,
			boolean isWrite) {
		JSONObject old_ret;
		JSONObject new_ret;
		String apiName;
		if (isTradeIsolation) {
			old_ret = SearchCompareAPI.old_GetProductListByTradeIsolation().search(productList);
			new_ret = SearchCompareAPI.new_GetProductListByTradeIsolation().search(productList);
			apiName = "GetProductListByTradeIsolation";
		} else {
			old_ret = SearchCompareAPI.old_GetProductListByProductIdList().search(productList);
			new_ret = SearchCompareAPI.new_GetProductListByProductIdList().search(productList);
			apiName = "GetProductListByProductIdList";
		}

		apiName = apiName + ", productId: " + productList.get(0);
		try {
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");

			List<ProductInListBean> old_ProductInDetailBeanList = new ArrayList<>();
			List<ProductInListBean> new_ProductInDetailBeanList = new ArrayList<>();

			for (int i = 0; i < old_prodList.length(); i++) {
				old_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),
						ProductInListBean.class));
				new_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),
						ProductInListBean.class));

			}
			System.out.println(apiName);
			// 返回值比对

			return new ProductReturnBean(old_ProductInDetailBeanList.get(0).getProductId(),
					SearchCompareHelper.compareProductInListBean(old_ProductInDetailBeanList.get(0),
							new_ProductInDetailBeanList.get(0),
							apiName, isWrite));
		} catch (Exception e) {
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;

	}

	public static ProductReturnBean coreCompareProductHistoryList(List<String> productList, boolean isWrite) {
		JSONObject old_ret = SearchCompareAPI.old_GetProductListByHistoryProductIdList().search(productList);
		JSONObject new_ret = SearchCompareAPI.new_GetProductListByHistoryProductIdList().search(productList);
		String apiName = "GetProductListByHistoryProductIdList,productId:" + productList.get(0);

		try {

			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");

			List<ProductHistoryBean> old_ProductHistoryBeanList = new ArrayList<>();
			List<ProductHistoryBean> new_ProductHistoryBeanList = new ArrayList<>();

			for (int i = 0; i < old_prodList.length(); i++) {
				old_ProductHistoryBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),
						ProductHistoryBean.class));
				new_ProductHistoryBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),
						ProductHistoryBean.class));

			}

			System.out.println(apiName);
			return new ProductReturnBean(old_ProductHistoryBeanList.get(0).getProductId(),
					SearchCompareHelper.compareProductHistoryBean(old_ProductHistoryBeanList.get(0),
							new_ProductHistoryBeanList.get(0),apiName, isWrite));

		} catch (Exception e) {
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;
	}

	// 比对
	public static ProductReturnBean coreCompareProductDescExtra(String productId, boolean isWrite) {

		JSONObject old_ret = SearchCompareAPI.old_GetProductDescExtraByProductId().search(Arrays.asList(productId));
		JSONObject new_ret = SearchCompareAPI.new_GetProductDescExtraByProductId().search(Arrays.asList(productId));
		String apiName = "GetProductDescExtraByProductId, ProductId:" + productId;

		try {
			if (!preCheckJSONObject(old_ret,new_ret,"ProductDescExtra",apiName,isWrite)){return null;}
			
			JSONObject old_prod = old_ret.getJSONObject("Data").getJSONObject("ProductDescExtra");
			JSONObject new_prod = new_ret.getJSONObject("Data").getJSONObject("ProductDescExtra");

			ProductDescExtraBean oldBean = ProductQueryCallService.getBeanFromJson(old_prod,
					ProductDescExtraBean.class);
			ProductDescExtraBean newBean = ProductQueryCallService.getBeanFromJson(new_prod,
					ProductDescExtraBean.class);

			// 返回值比对
			System.out.println(apiName);
			return new ProductReturnBean(oldBean.getProductId(), SearchCompareHelper
					.compareProductDescExtraBean(oldBean, newBean, apiName, isWrite));

		} catch (Exception e) {
			try {
				if (!old_ret.getJSONObject("Data").isNull("ProductDescExtra")){
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
				}
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;
	}

	// 比对
	public static List<ProductReturnBean> coreCompareProductInListForNew(String sellerId, boolean isWrite) {
		JSONObject old_ret = SearchCompareAPI.old_GetNewestProductListBySellerId().search(Arrays.asList(sellerId));
		JSONObject new_ret = SearchCompareAPI.new_GetNewestProductListBySellerId().search(Arrays.asList(sellerId));
		String apiName = "GetNewestProductListBySellerId, sellerId:" + sellerId;

		try {
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");

			List<ProductInListBean> old_ProductInDetailBeanList = new ArrayList<>();
			List<ProductInListBean> new_ProductInDetailBeanList = new ArrayList<>();

			for (int i = 0; i < old_prodList.length(); i++) {
				old_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),ProductInListBean.class));
			}
			
			for (int i = 0; i < new_prodList.length(); i++) {
				new_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),ProductInListBean.class));
			}

			// 返回值比对
			System.out.println(apiName);
			List<String> productList = old_ProductInDetailBeanList.stream().map(ele -> ele.getProductId()).collect(Collectors.toList());
			
			//剔除 删除商品
			old_ProductInDetailBeanList.removeAll(old_ProductInDetailBeanList.stream().filter(x->x.getStatus()==-1).collect(Collectors.toList()));
			
			return SearchCompareHelper.compareProductInListBean(productList,old_ProductInDetailBeanList,new_ProductInDetailBeanList,
					apiName, isWrite);
		} catch (Exception e) {
		
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}

		return null;
	}
	
	
	
	public static List<ProductReturnBean> coreCompareProductInListForHot(String sellerId,boolean isWrite)  {
		JSONObject	old_ret = SearchCompareAPI.old_GetHotRecmdProductListBySellerId().search(Arrays.asList(sellerId));
		JSONObject	new_ret = SearchCompareAPI.new_GetHotRecmdProductListBySellerId().search(Arrays.asList(sellerId));
		String	apiName = "GetHotRecmdProductListBySellerId, sellerId:" +sellerId;
		
		
		try{
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");
			
			List<ProductInListBean> old_ProductInDetailBeanList = new ArrayList<>();
			List<ProductInListBean> new_ProductInDetailBeanList = new ArrayList<>();
			
			for(int i=0;i<old_prodList.length();i++){
				old_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),ProductInListBean.class));
			}
			
			for(int i=0;i<new_prodList.length();i++){
				new_ProductInDetailBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),ProductInListBean.class));
			}
			
			//返回值比对
			System.out.println(apiName);
			List<String> productList = old_ProductInDetailBeanList.stream().map(ele->ele.getProductId()).collect(Collectors.toList());
			
			//剔除 删除商品
			old_ProductInDetailBeanList.removeAll(old_ProductInDetailBeanList.stream().filter(x->x.getStatus()==-1).collect(Collectors.toList()));
			
			return SearchCompareHelper.compareProductInListBean(productList,old_ProductInDetailBeanList,new_ProductInDetailBeanList,
					apiName, isWrite);
			
		}catch(Exception e){
			
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;
		
	}
	
	
	
	public static List<ProductReturnBean> coreCompareRecommendProductList(List<String> sellerIdList,boolean isWrite){
		JSONObject old_ret = SearchCompareAPI.old_GetSellerRecommendProductList().search(sellerIdList);
		JSONObject new_ret = SearchCompareAPI.new_GetSellerRecommendProductList().search(sellerIdList);
		String apiName = "GetSellerRecommendProductList"+"sellerId:"+sellerIdList.get(0);
		
		try{
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");
			
			List<RecommendProductBean> old_RecProductBeanList = new ArrayList<>();
			List<RecommendProductBean> new_RecProductBeanList = new ArrayList<>();
			
			for(int i=0;i<old_prodList.length();i++){
				old_RecProductBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),RecommendProductBean.class));
			}
			
			for(int i=0;i<new_prodList.length();i++){
				new_RecProductBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),RecommendProductBean.class));
			
			}
			
			System.out.println(apiName);
			return SearchCompareHelper.compareRecommendProductBean(old_RecProductBeanList,new_RecProductBeanList,apiName, isWrite);
			
		}catch(Exception e){
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		
		
		return null;
	}
	
	
	
	public static List<ProductReturnBean> coreCompareTopProductInLive(String liveId,boolean isWrite) {
		JSONObject	old_ret = SearchCompareAPI.old_GetTopProductListByLiveId().search(Arrays.asList(liveId));
		JSONObject	new_ret = SearchCompareAPI.new_GetTopProductListByLiveId().search(Arrays.asList(liveId));
		String	apiName = "GetTopProductListByLiveId, liveId:" +liveId;
		
		try{
			if (!preCheckJSONObject(old_ret,new_ret,"ProductList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("ProductList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("ProductList");
			
			List<TopProductInLiveBean> tgtTopProductInLiveBeanList = new ArrayList<>();
			List<TopProductInLiveBean> actTopProductInLiveBeanList = new ArrayList<>();
			
			for(int i=0;i<old_prodList.length();i++){
				tgtTopProductInLiveBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),TopProductInLiveBean.class));
			}
			
			for(int i=0;i<new_prodList.length();i++){
				actTopProductInLiveBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),TopProductInLiveBean.class));
			}
			
			
			//返回值比对
			System.out.println(apiName);
			List<String> productList = tgtTopProductInLiveBeanList.stream().map(ele->ele.getProductId()).collect(Collectors.toList());
			return SearchCompareHelper.compareTopProductInLiveBean(productList, tgtTopProductInLiveBeanList, actTopProductInLiveBeanList, 
					apiName, isWrite);
			
		}catch(Exception e){
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return null;
	}
	
	
	
	
	public static ProductReturnBean coreCompareSecKillProductActivityStock(String productId,String activityId,boolean isWrite)  {
		JSONObject	old_ret = SearchCompareAPI.old_GetSecKillProductActivityStock().search(Arrays.asList(productId,activityId));
		JSONObject	new_ret = SearchCompareAPI.new_GetSecKillProductActivityStock().search(Arrays.asList(productId,activityId));
		String	apiName = "GetSecKillProductActivityStock, activityId:" +activityId +", productId: "+ productId;
		
		try{
			if (!preCheckJSONObject(old_ret,new_ret,"StockList",apiName,isWrite)){return null;}
			
			JSONArray old_prodList = old_ret.getJSONObject("Data").getJSONArray("StockList");
			JSONArray new_prodList = new_ret.getJSONObject("Data").getJSONArray("StockList");
			
			List<SecKillProductActivityStockBean> old_ProdKillBeanList = new ArrayList<>();
			List<SecKillProductActivityStockBean> new_ProdKillBeanList = new ArrayList<>();
			
			for(int i=0;i<old_prodList.length();i++){
				old_ProdKillBeanList.add(ProductQueryCallService.getBeanFromJson(old_prodList.getJSONObject(i),SecKillProductActivityStockBean.class));
			}
			
			for(int i=0;i<new_prodList.length();i++){
				new_ProdKillBeanList.add(ProductQueryCallService.getBeanFromJson(new_prodList.getJSONObject(i),SecKillProductActivityStockBean.class));
			}
			
			
			//返回值比对
			System.out.println(apiName);
			return SearchCompareHelper.compareSecKillProductActivityStockBean(old_ProdKillBeanList, new_ProdKillBeanList,apiName,isWrite);
		}catch(Exception e){
			try {
				LoggerHelper.failure(apiName + ", " + e.getMessage()+",old msg:"+old_ret.getString("Msg")+",new msg:"+new_ret.getString("Msg"), true);
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
			
		}
		return null;
	}

}
